package io.renren.modules.shop.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.modules.shop.entity.CustomerMerchantVO;
import io.renren.modules.shop.service.CusMerchantService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.shop.entity.CustomerEntity;
import io.renren.modules.shop.service.CustomerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author Yangqianyong
 * @email sunlightcs@gmail.com
 * @date 2021-11-17 15:35:51
 */
@RestController
@RequestMapping("shop/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @Autowired
    private CusMerchantService cusMerchantService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("shop:customer:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = customerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{customerId}")
//    @RequiresPermissions("shop:customer:info")
    public R info(@PathVariable("customerId") Long customerId){
		CustomerEntity customer = customerService.getById(customerId);

        return R.ok().put("customer", customer);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("shop:customer:save")
    public R save(@RequestBody CustomerEntity customer){
		customerService.save(customer);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("shop:customer:update")
    public R update(@RequestBody CustomerEntity customer){
		customerService.updateById(customer);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("shop:customer:delete")
    public R delete(@RequestBody Long[] customerIds){
		customerService.removeByIds(Arrays.asList(customerIds));

        return R.ok();
    }

    @RequestMapping("/byId")
    public R getCustomer(@RequestParam Long id){
        CustomerEntity customer = customerService.getById(id);
        return R.ok().put("customer",customer);
    }

    @RequestMapping("/byPhone")
    public R getCustomerByPhone(@RequestParam Long phone){

        QueryWrapper<CustomerEntity> queryWrapper = new QueryWrapper<>();

        CustomerEntity customer = customerService
                .getOne(queryWrapper.lambda()
                        .eq(CustomerEntity::getMobilePhone,phone));

        return R.ok().put("customer",customer);
    }
//    @GetMapping("/byPhone1")
//    public R hello3( Long phone){
//        CustomerEntity customer = customerService.selectCustomerByTele(phone);
//        return R.ok().put("customer",customer);
//    }
//
//    @GetMapping("/byPhone2")
//    public R hello4( Long phone){
//
//        CustomerMerchantVO customerMerchantVO = cusMerchantService.getByPhone(phone);
//        return R.ok().put("customerMerchantVO",customerMerchantVO);
//    }


}



